package org.tony.entity;

import java.util.Iterator;
import java.util.Map;

import org.apache.commons.lang3.builder.ToStringBuilder;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;

/**
 * 数据定制实体的一个 属性，与数据定制实体是1对多的关系 ，具体可以参照生成后的数据定制模板文件
 * @author tony
 *
 */
public class RelationDataSourceEntry {
	
	private String fromDateSourceId ;
	private String fromTableName ;
	private String relationKey ;
	private Map<String,String> columns ;
	
	public String getFromDateSourceId() {
		return fromDateSourceId;
	}
	public void setFromDateSourceId(String fromDateSourceId) {
		this.fromDateSourceId = fromDateSourceId;
	}
	public String getFromTableName() {
		return fromTableName;
	}
	public void setFromTableName(String fromTableName) {
		this.fromTableName = fromTableName;
	}
	public String getRelationKey() {
		return relationKey;
	}
	public void setRelationKey(String relationKey) {
		this.relationKey = relationKey;
	}
	
	public Map<String, String> getColumns() {
		return columns;
	}
	public void setColumns(Map<String, String> columns) {
		this.columns = columns;
	}
	
	public Node generateNode(Document doc) {
		Element ele = doc.createElement("datasource") ;
		ele.setAttribute("from_ds", this.fromDateSourceId);
		ele.setAttribute("from_tb", this.fromTableName);
		ele.setAttribute("relation_key", this.relationKey);
		for(Iterator<Map.Entry<String, String>> iter = this.columns.entrySet().iterator();iter.hasNext();) {
			Map.Entry<String, String> cur = iter.next() ;
			Element cols = doc.createElement("column") ;
			cols.setAttribute("name", cur.getKey());
			cols.setAttribute("type", cur.getValue());
			ele.appendChild(cols);
		}
		return ele ;
	}
	/**
	 * @see java.lang.Object#toString()
	 */
	public String toString() {
		return new ToStringBuilder(this).append("fromDateSourceId",
				this.fromDateSourceId).append("relationKey", this.relationKey)
				.append("fromTableName", this.fromTableName).append("columns",
						this.columns).toString();
	}
	
}
